<?php	
//查询表所有数据
select * from student;
//查询出来的数据，关联数组
$data = array();
$data = [
	[
		"sid"=>1,
		"sname"=>"黄浩",
		"age"=>22,
		"sex"=>"男",
	],
	[
		"sid"=>1,
		"sname"=>"黄浩",
		"age"=>22,
		"sex"=>"男",
	],
];
//查询sname一列数据
select sname from student;
//as 别名
select sname as s from student;
select sname s from student;

//找年龄（age>30）所有人的姓名
select sname from student where age>30;
//查找age>30并且age<50的人姓名
select sname from student where age>30 and age<50;
//查找age<30 或者是 age>50的人姓名
select sname from student where age<30 or age>50;


//concat连接
select concat(sname,'|',age) as c from student;
//查询结果自身比较
select age,age>30 from student;
//去重
select distinct age from student;
select distinct sname,age from student;

//查找字段为null的数据
select * from student where sname is null;
//if使用
select age,if(age>30,"中年","骚年") from student;


//排序
//按照年龄大-->小进行降序排列
select * from student order by age desc; 
//按照年龄小-->大进行升序排列 
select * from student order by age asc;

//limit截取
//获取年龄较大的三条数据
select * from student order by age desc limit 3;
//从二号位置开始截取三条
select * from student order by age desc limit 2,3;
//获取年龄最大一个
select * from student order by age desc limit 1;


//按照两个字段排序
select * from student order by age desc,sid asc;


//between 30 and 50 包含30和50的
//select * from student where age>30 and age <50;
select * from student where age between 30 and 50;


//in(38,44,45)
//查找年龄是38、44、45的所有人
select * from student where age in (38,44,45);


//查找姓名中包含张【%匹配多个，_匹配一个】
select * from student where sname like "%张%";


//字符串截取
select left(sname,2) as l from student;
//right

//随机截取6条
select * from student order by rand() limit 6; 















